Skip to content

fix(cold-store-reaper): rebuild turso dumps with repeated tables and vector indexes - #12028

Merged
dezren39 merged 1 commit into
mainfrom
fix/turso-dump-repeated-table
Nov 19, 2026
Merged

dezren39 merged 1 commit into
mainfrom
fix/turso-dump-repeated-table

Conversation

@dezren39

@dezren39 dezren39 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Before: the nightly Turso export of the atlas database failed every night. libsql's /dump emits the vector table vec_snowflake_m_v2_768_f32 twice, byte for byte, so the sqlite3 rebuild stopped on the second copy's first primary key. Past that, the dump's last statement creates a libsql_vector_idx index, which stock sqlite3 can't run.

After: the atlas export rebuilds into a clean SQLite file. The repeated table copy is dropped (only when it matches the first copy exactly) and the vector index statement is kept as a row in cold_store_libsql_vector_indexes; the index data itself stays in its shadow tables.

How:

  • scripts/dedupe_dump.py streams the dump with constant memory. For each table it keeps a sha256 and count of its first block's INSERT lines; a second CREATE TABLE for the same table must have an identical definition, and its rows' hash and count must match, or the export fails (no row is ever dropped silently).
  • scripts/vector_index_dump.py replaces each single-line CREATE INDEX ... (libsql_vector_idx(...)) with an INSERT into cold_store_libsql_vector_indexes(name, sql). To restore into libsql, drop the index's shadow table and its libsql_vector_meta_shadow row, then run the recorded statement.
  • export-turso.sh pipes repair_dump.py | dedupe_dump.py | vector_index_dump.py.

Tested on the live atlas dump (13.5 GB, read-only token, Nov 19): the filter dropped one repeated copy of 107,639 identical rows, the rebuild passed integrity_check, the vec table has 107,639 distinct chunk_ids, all 14 user tables are present, and the file is 7.3 GB (about 3.6 GB gzipped). Unit tests: 47 pass across the dedupe, vector-index, export, repair and nightly suites.

Refs #12000


Generated by Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…vector indexes

libsql's /dump of the atlas database emits the vector table
vec_snowflake_m_v2_768_f32 twice, byte for byte, so the sqlite3
rebuild stopped on the second copy's first primary key. Its last
statement also creates a libsql_vector_idx index, which stock sqlite3
cannot run.

dedupe_dump.py drops a repeated table block only when its CREATE and
every row match the first copy (sha256 and count), and fails the
export when they differ. vector_index_dump.py records each libsql
vector index statement in cold_store_libsql_vector_indexes instead of
running it; the index data stays in its shadow tables.

Refs #12000

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 marked this pull request as ready for review November 19, 2026 07:17
@dezren39
dezren39 requested a review from a team as a code owner November 19, 2026 07:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T07:22:31.756942Z d878073 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 5fee229 into main Nov 19, 2026
1 check failed
@dezren39
dezren39 deleted the fix/turso-dump-repeated-table branch November 19, 2026 07:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8780735c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +130 to +131
block = original = None
match = CREATE.match(line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Track SQL literal context before dropping repeated CREATEs

When a multiline text value contains a line identical to an earlier empty table's CREATE statement, this physical-line match mistakes the text for a repeated table block. For example, after CREATE TABLE IF NOT EXISTS empty (x);, a later INSERT INTO notes VALUES('before\nCREATE TABLE IF NOT EXISTS empty (x);\nafter'); loses the embedded CREATE line: both apparent empty-table blocks have matching zero-row digests. The resulting INSERT remains valid, so the export passes COMMIT and integrity checks while silently corrupting the stored text. Track statement/string-literal context before recognizing table blocks; the new vector-index filter needs the same protection before rewriting physical lines.

Useful? React with 👍 / 👎.

Comment on lines +50 to +53
def main():
out = sys.stdout.buffer
created = False
for line in sys.stdin.buffer:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject unexpected arguments before processing either filter

Both new scripts enter their stdin-processing loops without inspecting command-line arguments, so an invocation with an unknown flag or stray positional silently performs the transformation and exits successfully rather than reporting a usage error. This violates the operator-script argument contract in AGENTS.md, which requires strict argument validation before output or other effects. Declare that these filters accept no arguments and reject unexpected arguments with a nonzero exit before consuming stdin or writing stdout.

AGENTS.md reference: AGENTS.md:L47-L51

Useful? React with 👍 / 👎.

import sys

CREATE = re.compile(
rb'^CREATE TABLE (?:IF NOT EXISTS )?("(?:[^"]|"")+"|\'(?:[^\']|\'\')+\'|[A-Za-z_][A-Za-z0-9_]*)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match complete identifiers before comparing table definitions

For valid unquoted SQLite identifiers containing $ or non-ASCII characters, this regex captures only the ASCII prefix without checking that the identifier ends there. Distinct declarations such as CREATE TABLE IF NOT EXISTS foo$one(x); and CREATE TABLE IF NOT EXISTS foo$two(y); are therefore both recorded as table foo. The second declaration triggers the differing-definition error and aborts an otherwise valid export even though there is no repeated table; these declarations passed through the previous pipeline unchanged. Match the complete identifier, or leave unsupported identifier forms untouched rather than registering a partial name.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants